package com.ld.wms.business.material.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ld.wms.business.material.mapper.FieldInfoMapper;
import com.ld.wms.business.material.model.FieldInfoModel;
import com.ld.wms.business.material.service.FieldInfoService;
import com.ld.wms.business.material.vo.req.FieldInfoReqVo;
import com.ld.wms.business.material.vo.resp.FieldInfoRespVo;
import com.ld.wms.common.vo.GeneratePageListVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 自定义字段表 服务实现类
 * </p>
 *
 * @author wangfeng
 * @since 2025-02-26
 */
@Service
public class FieldInfoServiceImpl extends ServiceImpl<FieldInfoMapper, FieldInfoModel> implements FieldInfoService {

    @Autowired
    private FieldInfoMapper fieldInfoMapper;

    @Override
    public GeneratePageListVo<FieldInfoRespVo> getPageList(String name, Integer current, Integer size) {
        IPage<FieldInfoRespVo> iPage = new Page<>(current, size);
        IPage<FieldInfoRespVo> iPage1 = fieldInfoMapper.selectPageList(iPage, name);
        return new GeneratePageListVo<>(iPage1);
    }

    @Override
    public void add(FieldInfoReqVo reqVo) {
        FieldInfoModel fieldInfoModel = new FieldInfoModel();
        BeanUtils.copyProperties(reqVo, fieldInfoModel);
        fieldInfoMapper.insert(fieldInfoModel);
    }

    @Override
    public void updateById(FieldInfoReqVo reqVo) {
        FieldInfoModel fieldInfoModel = new FieldInfoModel();
        BeanUtils.copyProperties(reqVo, fieldInfoModel);
        fieldInfoMapper.updateById(fieldInfoModel);
    }

    @Override
    public void deleteById(Long id) {
        fieldInfoMapper.deleteById(id);
    }

    @Override
    public FieldInfoRespVo getById(Long id) {
        FieldInfoRespVo fieldInfoRespVo = new FieldInfoRespVo();
        FieldInfoModel fieldInfoModel = fieldInfoMapper.selectById(id);
        BeanUtils.copyProperties(fieldInfoModel, fieldInfoRespVo);
        return fieldInfoRespVo;
    }
}

